package com.yulongtian.algorithms.binarysearch01;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/find-the-distance-value-between-two-arrays/
 * 可
 *
 * @author yulongTian
 * @create 2023-02-02 10:48
 */
public class Test05 {
    public static void main(String[] args) {
        int[] arr1 = {1, 4, 2, 3};
        int[] arr2 = {-4, -3, 6, 10, 20, 30};
        System.out.println(findTheDistanceValue(arr1, arr2, 3));
    }

    public static int findTheDistanceValue(int[] arr1, int[] arr2, int d) {

        //排序
        Arrays.sort(arr1);
        Arrays.sort(arr2);

        int ans = 0;

        for (int i = 0; i < arr1.length; i++) {
            boolean flag = true;
            for (int j = 0; j < arr2.length; j++) {
                if (Math.abs(arr1[i] - arr2[j]) <= d) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                ans++;
            }
        }
        return ans;
    }


}
